<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>回调形式的refs</title>
  </head>

  <body>
    <div id="test"></div>

    <script type="text/javascript" src="../js/react.development.js"></script>
    <script
      type="text/javascript"
      src="../js/react-dom.development.js"
    ></script>
    <script type="text/javascript" src="../js/babel.min.js"></script>

    <script type="text/babel">
      class Demo extends React.Component {

        /* 
				 React.createRef调用后可以返回一个容器，该容器可以存储被ref所标识的节点,该容器是“专人专用”的
			  */
        myRef = React.createRef();
        myRef2 = React.createRef();

        render() {
          return (
            <div>
              <input ref={this.myRef} type="text" placeholder='点击按钮提示'/>&nbsp;
              <button onClick={this.showDate}>点击提示左侧数据</button>&nbsp;
              <input ref={this.myRef2} onBlur={this.showDate2}  type="text" placeholder='失去焦点提示'/>
            </div>
          );
        }

        showDate = () =>{
          alert(this.myRef.current.value)
        } 
        showDate2 = () =>{
          alert(this.myRef2.current.value)
        } 
       
      }

      ReactDOM.render(<Demo />, document.getElementById("test"));
    </script>
  </body>
</html>
